<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AuthController extends Controller
{
    /**
     * 发送验证码
     */
    public function sendCode(Request $request){
        $phone = $request->input('phone');
        $this->sendAuthCode($phone);
    }

    /**
     * 校验手机号码
     */
    public function checkCode(Request $request){
        $phone = $request->input('phone');
        $code =  $request->input('code');
        $redis = $this->initRedis(0);
        $trueCodeArr = $redis->smembers($phone);
        foreach ($trueCodeArr as $item) {
            if($item == $code){
                //删除已校验的验证码
                $redis->spop($phone);
                return $this->success(true,'验证码无误');
            }
        }



        return $this->error(5001,'验证码错误');
    }

}
